package com.kgc.personconsumer.controller;

import com.kgc.basic.util.ResponseMsg;
import com.kgc.personcommon.pojo.Role;
import com.kgc.personconsumer.feign.RoleFeign;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/role")
public class RoleController {
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private RoleFeign roleFeign;

    @RequestMapping("getPage")
    @ResponseBody
    public ResponseMsg getPage(String pageNow, String pageSize, String name,String department) {
        logger.info("RoleController getPage pageNow:"+pageNow+",pageSize:"+pageSize+",department:"+department+",name:"+name);
        Map<String,Object> map = new HashMap<>();
        map.put("name",name);
        map.put("department",department);
        map.put("pageNow",pageNow);
        map.put("pageSize",pageSize);
        ResponseMsg responseMsg =roleFeign.getRolePage(map);
        logger.debug("roleFeign getPage responseMsg:"+responseMsg+",map:"+map);
        return responseMsg;
    }
    @RequestMapping("add")
    @ResponseBody
    public ResponseMsg addRole(@RequestBody Role role) {
        logger.info("RoleController addRole role:"+role);
        ResponseMsg responseMsg = roleFeign.addRole(role);
        logger.debug("roleFeign addRole responseMsg:"+responseMsg+",role:"+role);
        return responseMsg;
    }
    @RequestMapping("update")
    @ResponseBody
    public ResponseMsg updateRole(@RequestBody Role role) {
        logger.info("RoleController updateRole role:"+role);
        ResponseMsg responseMsg = roleFeign.updateRole(role);
        logger.debug("roleFeign updateRole responseMsg:"+responseMsg+",role:"+role);
        return responseMsg;
    }
    @RequestMapping("del")
    @ResponseBody
    public ResponseMsg delRole(@RequestParam("id") String id) {
        logger.info("RoleController delRole id:"+id);
        ResponseMsg responseMsg = roleFeign.delRole(id);
        logger.debug("roleFeign delRole responseMsg:"+responseMsg+",id:"+id);
        return responseMsg;
    }

    @RequestMapping("getById")
    @ResponseBody
    public ResponseMsg getById(@RequestParam("id") String id) {
        logger.info("RoleController getById id:"+id);
        ResponseMsg responseMsg = roleFeign.getRoleById(id);
        logger.debug("roleFeign getRoleById responseMsg:"+responseMsg+",id:"+id);
        return responseMsg;
    }

    @RequestMapping("getAll")
    @ResponseBody
    public ResponseMsg getAll() {
        logger.info("RoleController getAll role");
        Map<String,Object> map = new HashMap<>();
        ResponseMsg responseMsg = roleFeign.getAllRole(map);
        logger.debug("roleFeign getAllRole responseMsg:"+responseMsg+",map:"+map);
        return responseMsg;
    }
}